from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-06-03 14:02:37.364044
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Fri, 03, Jun, 2022
Time: 14:02:43
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -49.4952
Nobs: 676.000 HQIC: -49.8637
Log likelihood: 8389.79 FPE: 1.75140e-22
AIC: -50.0965 Det(Omega_mle): 1.53458e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.305680 0.059454 5.141 0.000
L1.Burgenland 0.105753 0.038453 2.750 0.006
L1.Kärnten -0.109286 0.020243 -5.399 0.000
L1.Niederösterreich 0.197427 0.080116 2.464 0.014
L1.Oberösterreich 0.124267 0.079183 1.569 0.117
L1.Salzburg 0.255351 0.040949 6.236 0.000
L1.Steiermark 0.046522 0.053656 0.867 0.386
L1.Tirol 0.105408 0.043421 2.428 0.015
L1.Vorarlberg -0.060561 0.038265 -1.583 0.113
L1.Wien 0.034173 0.070137 0.487 0.626
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.039960 0.126154 0.317 0.751
L1.Burgenland -0.032712 0.081592 -0.401 0.688
L1.Kärnten 0.039822 0.042954 0.927 0.354
L1.Niederösterreich -0.184391 0.169996 -1.085 0.278
L1.Oberösterreich 0.444954 0.168016 2.648 0.008
L1.Salzburg 0.284990 0.086888 3.280 0.001
L1.Steiermark 0.108006 0.113851 0.949 0.343
L1.Tirol 0.314923 0.092134 3.418 0.001
L1.Vorarlberg 0.025774 0.081195 0.317 0.751
L1.Wien -0.033708 0.148823 -0.226 0.821
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.184941 0.030507 6.062 0.000
L1.Burgenland 0.088565 0.019731 4.489 0.000
L1.Kärnten -0.007800 0.010387 -0.751 0.453
L1.Niederösterreich 0.255986 0.041108 6.227 0.000
L1.Oberösterreich 0.150643 0.040630 3.708 0.000
L1.Salzburg 0.044429 0.021011 2.115 0.034
L1.Steiermark 0.024504 0.027532 0.890 0.373
L1.Tirol 0.086203 0.022280 3.869 0.000
L1.Vorarlberg 0.054202 0.019634 2.761 0.006
L1.Wien 0.119476 0.035988 3.320 0.001
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.108941 0.030746 3.543 0.000
L1.Burgenland 0.043689 0.019885 2.197 0.028
L1.Kärnten -0.013820 0.010469 -1.320 0.187
L1.Niederösterreich 0.183294 0.041431 4.424 0.000
L1.Oberösterreich 0.321774 0.040948 7.858 0.000
L1.Salzburg 0.103028 0.021176 4.865 0.000
L1.Steiermark 0.109774 0.027747 3.956 0.000
L1.Tirol 0.098778 0.022454 4.399 0.000
L1.Vorarlberg 0.062666 0.019788 3.167 0.002
L1.Wien -0.018986 0.036271 -0.523 0.601
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.119008 0.056747 2.097 0.036
L1.Burgenland -0.045764 0.036702 -1.247 0.212
L1.Kärnten -0.046411 0.019322 -2.402 0.016
L1.Niederösterreich 0.143248 0.076469 1.873 0.061
L1.Oberösterreich 0.159282 0.075578 2.108 0.035
L1.Salzburg 0.282030 0.039085 7.216 0.000
L1.Steiermark 0.052780 0.051213 1.031 0.303
L1.Tirol 0.166088 0.041444 4.008 0.000
L1.Vorarlberg 0.096734 0.036523 2.649 0.008
L1.Wien 0.075423 0.066944 1.127 0.260
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.058283 0.044840 1.300 0.194
L1.Burgenland 0.030384 0.029001 1.048 0.295
L1.Kärnten 0.051456 0.015268 3.370 0.001
L1.Niederösterreich 0.203602 0.060424 3.370 0.001
L1.Oberösterreich 0.314857 0.059720 5.272 0.000
L1.Salzburg 0.042137 0.030884 1.364 0.172
L1.Steiermark 0.009059 0.040468 0.224 0.823
L1.Tirol 0.133109 0.032748 4.065 0.000
L1.Vorarlberg 0.068340 0.028860 2.368 0.018
L1.Wien 0.089412 0.052898 1.690 0.091
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.167013 0.053671 3.112 0.002
L1.Burgenland 0.005857 0.034712 0.169 0.866
L1.Kärnten -0.065202 0.018274 -3.568 0.000
L1.Niederösterreich -0.093233 0.072323 -1.289 0.197
L1.Oberösterreich 0.198685 0.071480 2.780 0.005
L1.Salzburg 0.055653 0.036966 1.506 0.132
L1.Steiermark 0.238822 0.048437 4.931 0.000
L1.Tirol 0.503377 0.039197 12.842 0.000
L1.Vorarlberg 0.062282 0.034543 1.803 0.071
L1.Wien -0.070863 0.063315 -1.119 0.263
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.148947 0.059861 2.488 0.013
L1.Burgenland 0.001223 0.038716 0.032 0.975
L1.Kärnten 0.060345 0.020382 2.961 0.003
L1.Niederösterreich 0.185966 0.080665 2.305 0.021
L1.Oberösterreich -0.067748 0.079725 -0.850 0.395
L1.Salzburg 0.209502 0.041229 5.081 0.000
L1.Steiermark 0.131979 0.054024 2.443 0.015
L1.Tirol 0.073409 0.043718 1.679 0.093
L1.Vorarlberg 0.146033 0.038528 3.790 0.000
L1.Wien 0.112494 0.070618 1.593 0.111
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.374237 0.035260 10.614 0.000
L1.Burgenland -0.002203 0.022805 -0.097 0.923
L1.Kärnten -0.022230 0.012005 -1.852 0.064
L1.Niederösterreich 0.214353 0.047514 4.511 0.000
L1.Oberösterreich 0.222005 0.046960 4.728 0.000
L1.Salzburg 0.040958 0.024285 1.687 0.092
L1.Steiermark -0.016000 0.031821 -0.503 0.615
L1.Tirol 0.097895 0.025751 3.802 0.000
L1.Vorarlberg 0.056715 0.022694 2.499 0.012
L1.Wien 0.036162 0.041596 0.869 0.385
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.037175 0.122880 0.180849 0.144252 0.104310 0.086873 0.040061 0.213797
Kärnten 0.037175 1.000000 -0.018818 0.133517 0.052788 0.091798 0.440916 -0.059490 0.094287
Niederösterreich 0.122880 -0.018818 1.000000 0.328687 0.132280 0.285828 0.081234 0.167090 0.306016
Oberösterreich 0.180849 0.133517 0.328687 1.000000 0.221199 0.313045 0.172683 0.158272 0.259080
Salzburg 0.144252 0.052788 0.132280 0.221199 1.000000 0.131766 0.101814 0.118003 0.133262
Steiermark 0.104310 0.091798 0.285828 0.313045 0.131766 1.000000 0.143557 0.122411 0.057944
Tirol 0.086873 0.440916 0.081234 0.172683 0.101814 0.143557 1.000000 0.078275 0.153411
Vorarlberg 0.040061 -0.059490 0.167090 0.158272 0.118003 0.122411 0.078275 1.000000 0.016366
Wien 0.213797 0.094287 0.306016 0.259080 0.133262 0.057944 0.153411 0.016366 1.000000